package com.app.manage.utils;

import org.apache.commons.lang3.StringUtils;

import java.io.File;

public class FileSizeTranUtils {


    public static String kbTo(long fileSizeInBytes ){
        long gb = fileSizeInBytes / (1024 * 1024 * 1024);  // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024Bytes
        long remainingMb = (fileSizeInBytes % (1024 * 1024 * 1024)) / (1024 * 1024); // 剩余的 MB
        String value = zh(gb == 0?null:gb+"GB",remainingMb == 0 ?null:remainingMb+"Mb");
        if(StringUtils.isEmpty(value)){
            //Kb级别
           return DataUtils.biDiv(2,String.valueOf(fileSizeInBytes),String.valueOf(1024),null)+"kb";
        }
        return value;
    }


    private static String  zh(String... a ){
        StringBuilder sb = new StringBuilder();
        for(String s : a){
            if(StringUtils.isNotEmpty(s)){
                sb.append(s);
            }
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        System.err.println(kbTo(new File("C:\\Users\\86173\\Desktop\\Paxos算法.doc").length()));
    }
}
